#ifndef _CAN_APP_H_
#define _CAN_APP_H_

#include "tx_api.h"

#define CAN1_RX0_BUF_LEN (50)
#define CAN1_RX1_BUF_LEN (50)

#pragma pack(1)

union can_message_data {
    volatile unsigned long long all;
    volatile unsigned int       word[2];
    volatile unsigned char      byte[8];
};

struct can_message {
    union can_message_data data;
    unsigned int           exid;
};

struct can1_rx0_buf_info {
    unsigned           tail;
    unsigned           head;
    struct can_message buf[CAN1_RX0_BUF_LEN];
};

struct can1_rx1_buf_info {
    unsigned           tail;
    unsigned           head;
    struct can_message buf[CAN1_RX1_BUF_LEN];
};

#pragma pack()

extern struct can1_rx0_buf_info can1_rx0_buf;
extern TX_THREAD                can1_rx0_thread_handle;
extern unsigned char            can1_rx0_thread_stack[4096];

extern TX_THREAD     can1_rx1_thread_handle;
extern unsigned char can1_rx1_thread_stack[1024];

extern TX_THREAD     state_manage_thread_handle;
extern unsigned char state_manage_thread_stack[1024];

extern TX_THREAD     upload_operate_parm_thread_handle;
extern unsigned char upload_operate_parm_thread_stack[1024];

void can1_rx0_thread(ULONG arg);
void can1_rx1_thread(ULONG thread_input);
void state_manage_thread(ULONG arg);

void                   init_can_app_var(void);
void                   init_adc_check_err_cnt(void);
Function_State_Typedef Can_Laser_PARA_Reply(struct can_message *msg, uint16_t Command, uint8_t *p, uint8_t PARA_Num);
Function_State_Typedef Can_Command_Reply(struct can_message *msg, Function_State_Typedef Can_State);
Function_State_Typedef Can_Ready_Command_Dipose(uint8_t Command);
Function_State_Typedef Can_Open_Control_Command_Dipose(uint8_t Command);
Function_State_Typedef Can_Close_Control_Command_Dipose(void);
Function_State_Typedef Can_Reset_Command_Dipose(void);
Function_State_Typedef seedReport(uint8_t data);

void                   flash_parm_to_configurable_parm(void);
int                    can1_send(struct can_message *msg);
Function_State_Typedef Laser_Open_Success_Reply(unsigned int id);
void                   upload_operate_parm_thread(ULONG arg);

#endif
